<?
class nieuwsController extends inabuurt_controller_action{

	public function indexAction(){
		$this -> view -> addStyle(view::PATH_TO_STYLE.'nieuws.css');
		$this -> view -> setTpl('nieuws_bericht.php');
		
		$crumbs = $this -> view -> breadcrumb;
		
		if($this -> request -> getParam(1) != NULL){
			
			$this -> loadBericht($this -> request -> getParam(1));
			$crumbs[] = array($this -> request -> formatParam(0),'/nieuws/'.$this -> request -> getParam(0).'/'.$this -> request -> getParam(0).'/');
		}else{
		
			$this -> initArchief();
		
		}
		
		$this -> view -> breadcrumb = $crumbs;
		$this -> updateTitle();
		$this -> view -> render();
	
	}

	private function loadBericht($id){
		
		$this -> view -> setTpl('nieuws_bericht.php');
		
		
		
		
		$bericht = new item_nieuws($this -> conn);
		
		$bericht -> id = $id;
		$bericht -> fill();
		
		$this -> view -> nieuws = $bericht;
		
		
		
	
	}
	
	private function initArchief(){
		require_once('./application/models/nieuwsModel.php');
		
		$model = nieuwsModel::getInstance($this -> conn);
		
		
		$itemsPerPage = 10;
		$total = $model -> getAantalBerichten();
		
		$pages = ceil($total / $itemsPerPage);
		
		
		if($this -> request -> getParam(0) != NULL && $this -> request -> getParam(0) <= $pages && $this -> request -> getParam(0) > 0){
			
			$page = $this -> request -> getParam(0);
			
			
		}else{
			$page = 1;
		}
		
		if($page + 1 <= $pages){
		
		$this -> view -> nextPage = $page + 1;
		}
		
		if($page - 1 > 0){
		$this -> view -> prevPage = $page - 1;
		}
		
		
		$berichten = $model -> getNieuws(($page * $itemsPerPage) - $itemsPerPage, $itemsPerPage);
		

		$this -> view -> nieuwsberichten = $berichten;
		
		
	}





}



?>